开始开发

本文档将指导您以最简单的方式将您的 DApp 与 TronLink 应用程序连接起来。DApp 加载后,TronLink 会将“window.tronLink”对象注入其中。

  1. 已经连接到该DApp的用户可以直接获得tronLink.tronWeb。
  2. 如果用户之前没有连接过这个DApp,可以在获取tronLink.tronWeb之前调用请求建立连接。

复制

async function getTronWeb() {
  let tronWeb;
  if (window.tronLink.ready) {
    tronWeb = tronLink.tronWeb;
  } else {
    const res = await tronLink.request({ method: 'tron_requestAccounts' });
    if (res.code === 200) {
      tronWeb = tronLink.tronWeb;
    }
  }
  return tronWeb;
}

获取tronWeb实例后,即可进行转账签名、多重签名交易、消息签名等链上交互操作。tronWeb实例的使用案例





Would you like to share your thoughts?

Your email address will not be published. Required fields are marked *